package com.framework.modules.job.task;

import com.framework.entity.log.LogAccount;
import com.framework.service.TransactionInfoService;
import com.framework.utils.MD5Util;
import com.framework.utils.httpClient.HttpLogin;
import com.framework.utils.jiufu.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 功能描述: 乐刷VIP激活返现
 *
 * @author ck
 * @date 2018/12/5 13:19
 */
@Component("leShuaVipTask")
public class LeShuaVipTask {

	private Logger logger = LoggerFactory.getLogger(getClass());

	@Autowired
	private TransactionInfoService transactionService;
	@Autowired
	private TransactionInfoService transactionInfoService;

	protected void addLeShuaVip() {
		logger.info("乐刷VIP返现定时器开始=======================addLeShuaVip");
		//查询所有渠道下面的乐刷账户信息
		List<LogAccount> list = transactionInfoService.queryTerAccountList(5);
		for (int i = 0; i < list.size(); i++) {
			//登录账号
			String userName = list.get(i).getUserName();
			//密码
			String password = list.get(i).getPassword();
			//账号id
			Long accountId = list.get(i).getAccountId();
			//说明
			String expInfo = list.get(i).getExpInfo();
			//二维码地址
			String imgCodeUrl = list.get(i).getImgCodeUrl();
			//登录地址
			String loginUrl = list.get(i).getLoginUrl();
			//MD5加密
			password = MD5Util.string2MD5(password).toUpperCase();
			String sessionId = HttpLogin.leShuaLogin(1,userName,password,loginUrl,imgCodeUrl);
			if(StringUtils.isBlank(sessionId)){
				//添加失败日志
				transactionInfoService.insertFailTerLog(expInfo+"-VIP激活返现",accountId);
			}else{
				transactionService.addLeShuaVip(sessionId,accountId,expInfo+"VIP激活返现");			}
		}
		logger.info("乐刷VIP返现定时器开始=======================addLeShuaVip");
	}
}
